using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Common = Microsoft.ConnectionEngine.Registers.Health.Patient.Common;

namespace Microsoft.ConnectionEngine.Registers.Health.Patient.DataAccess
{
    public class PersonName
    {

        #region Update/Insert

        /// <summary>
        /// Inserts a New PersonName Record
        /// </summary>
        /// <returns>Returns a PersonName ID</returns>
        public static int PersonNameInsert(string sPatientID,
                                                bool sPrimaryAliasIndicator,
                                                string sTitle,
                                                string sFamilyName,
                                                string sGivenName1,
                                                string sGivenName2,
                                                string sGivenName3,
                                                string sUpdateUserID,
                                                int iPreferredGivenNameIndex)
        {
            string SQL = DataAccessResources.NameInsertProc;
            Database db = DatabaseFactory.CreateDatabase(DataAccessHelper.GetDefaultConnectionStringName());

            SqlCommand dbCommand = new SqlCommand();
            dbCommand.CommandText = SQL;
            dbCommand.CommandType = CommandType.StoredProcedure;

	        dbCommand.Parameters.AddWithValue("@PrimaryAliasIndicator", DataAccessHelper.IfNull(sPrimaryAliasIndicator));
	        dbCommand.Parameters.AddWithValue("@Title", DataAccessHelper.IfNull(sTitle));
	        dbCommand.Parameters.AddWithValue("@FamilyName", DataAccessHelper.IfNull(sFamilyName));
	        dbCommand.Parameters.AddWithValue("@GivenName1", DataAccessHelper.IfNull(sGivenName1));
	        dbCommand.Parameters.AddWithValue("@GivenName2", DataAccessHelper.IfNull(sGivenName2));
	        dbCommand.Parameters.AddWithValue("@GivenName3", DataAccessHelper.IfNull(sGivenName3));
	        dbCommand.Parameters.AddWithValue("@UpdateUserID", DataAccessHelper.IfNull(sUpdateUserID));
	        dbCommand.Parameters.AddWithValue("@PreferredGivenNameIndex", DataAccessHelper.IfNull(iPreferredGivenNameIndex));
            dbCommand.Parameters.AddWithValue("@PatientID", DataAccessHelper.IfNull(sPatientID));

            int sNewNameID = Convert.ToInt32(db.ExecuteScalar(dbCommand));

            return sNewNameID;

        }

        #endregion
    
    
    }
}
